<?php

namespace App\Http\Requests\Admin;

use Illuminate\Foundation\Http\FormRequest;

class CategoryRequest extends FormRequest
{
    /**
     * Determine if the user is authorized to make this request.
     */
    public function authorize(): bool
    {
        return true;
    }

    /**
     * Get the validation rules that apply to the request.
     *
     * @return array<string, \Illuminate\Contracts\Validation\ValidationRule|array<mixed>|string>
     */
    public function rules(): array
    {
        $categoryId = $this->route('id');
        
        return [
            'name' => 'required|string|max:50',
            'slug' => 'required|string|max:50|unique:categories,slug,' . $categoryId,
            'description' => 'nullable|string',
            'sort_order' => 'integer|min:0',
            'is_active' => 'boolean'
        ];
    }

    /**
     * Get custom messages for validator errors.
     */
    public function messages(): array
    {
        return [
            'name.required' => '分类名称不能为空',
            'name.max' => '分类名称不能超过50个字符',
            'slug.required' => '分类标识不能为空',
            'slug.unique' => '分类标识已存在',
            'slug.max' => '分类标识不能超过50个字符',
            'sort_order.integer' => '排序必须是整数',
            'sort_order.min' => '排序不能小于0',
            'is_active.boolean' => '启用状态必须是布尔值',
        ];
    }
}
